﻿Public Class FMPengaturanAwal

    'member variables
    Private _cSemester As CSemester
    Private _semesterAktif As DataTable

    'forms
    Private WithEvents _flSemester As FLSemester

    'properties
    Public Property SelectedIDSemester As Integer
    Public Property SelectedNamaSemester As String

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.Text = My.Settings.NamaAplikasi & " [Pengaturan Awal]"
    End Sub

    Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click
        Me.Close()
    End Sub

    Private Sub BTNCariGuru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNCariSemester.Click
        _flSemester = New FLSemester
        _flSemester.ShowDialog()
    End Sub

    Private Sub _flSemester_DataTerpilih() Handles _flSemester.DataTerpilih
        'set data semester terpilih
        Me.SelectedIDSemester = _flSemester.SelectedIDSemester
        Me.SelectedNamaSemester = _flSemester.SelectedNamaSemester
        'tampilkan ke control
        TBNama.Text = Me.SelectedNamaSemester
    End Sub

    Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
        'simpan pengaturan semester aktif
        Try
            _cSemester = New CSemester
            _cSemester.setAktifSemester(Me.SelectedIDSemester)
            MessageBox.Show("Data tersimpan.", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        'simpan setting direktori foto
        My.Settings.DirektoriFoto = TBFoto.Text.Trim
        My.Settings.Save()

    End Sub

    Private Sub FMPengaturanAwal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'menampilkan semester aktif
        _cSemester = New CSemester
        _semesterAktif = _cSemester.getSemesterAktif
        'set ke properties
        Me.SelectedIDSemester = _semesterAktif(0).Item("id")
        Me.SelectedNamaSemester = _semesterAktif(0).Item("nama")
        'tampilkan ke control
        TBNama.Text = Me.SelectedNamaSemester

        'tampilkan setting direktori foto
        TBFoto.Text = My.Settings.DirektoriFoto
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNDirektori.Click
        If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            TBFoto.Text = FolderBrowserDialog1.SelectedPath
        End If
    End Sub
End Class